package com.shareppy.norman.core.queries;

import java.util.List;

import com.shareppy.norman.core.db.CursorWrapper;
import com.shareppy.norman.core.entity.AbstractEntity;
import com.shareppy.norman.core.sql.QueryBuilder;
import com.shareppy.norman.core.util.EntityUtils;

public class EntityQuery<E extends AbstractEntity> implements
		ComplexQuery<E, List<E>> {

	private E entity;

	public EntityQuery(E entity) {
		this.entity = entity;
	}

	@SuppressWarnings("unchecked")
	@Override
	public QueryBuilder getQuery() {
		QueryBuilder queryBuilder = QueryBuilder.get().from(entity.getClass());
		return customOperations( queryBuilder );
	}

	public QueryBuilder customOperations(QueryBuilder queryBuilder) {
		return queryBuilder;
	}

	@Override
	public List<E> transform(CursorWrapper<?> cursor) throws Exception {
		return EntityUtils.cursorToList(entity,
				EntityUtils.getColumnArray(null, entity), cursor);
	}

	public E getEntity() {
		return entity;
	}

	@Override
	public Object[] getParameters() {
		return null;
	}
}